package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SpringLayout;

public class PanelCongeUI extends AbstractParamPane implements ActionListener {
	
	String[] conges = {"Congé1", "Congé2", "Congé3", "Congé4"}; 
    JButton ajouter, modifier, supprimer;
    JList list;
	
	public PanelCongeUI() {
	
		//Create and populate the panel.
        setLayout(new BorderLayout());
		setBorder(BorderFactory.createCompoundBorder(
				BorderFactory.createTitledBorder("Congés"),
				BorderFactory.createEmptyBorder(5,5,5,5)));

		list = new JList (conges);
        add(list);
        
        ajouter = new JButton ("Ajouter");
        modifier= new JButton ("Modifier");
        supprimer = new JButton ("Supprimer");
        
        ajouter.addActionListener(this);
        modifier.addActionListener(this);
        supprimer.addActionListener(this);

        JPanel commandBox = new JPanel();
        commandBox.add(ajouter);
        commandBox.add(modifier);
        commandBox.add(supprimer);
        
        drawCommandBox(commandBox);
	}


	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() == ajouter) {
			PanelCongeUIConsulter panel = new PanelCongeUIConsulter(AbstractViewPane.ViewMode.AJOUT);
			panel.setVisible(true);
		}
		if (e.getSource() == modifier) {
			if (list.getSelectedIndex() != -1) {
				PanelCongeUIConsulter panel = new PanelCongeUIConsulter(AbstractViewPane.ViewMode.MODIFICATION);
				panel.setVisible(true);
			}
		}
		if (e.getSource() == supprimer) {
			if (list.getSelectedIndex() != -1) {
				JOptionPane.showConfirmDialog(
					    this,
					    "Êtes vous sûr de vouloir supprimer ce congé\n"+
					    //ensBL.getName()+" "+ensBL.getPrenom()+
					    " ?",
					    "Avertissement",
					    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
			}
		}		
	}
}
